﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LGCourt.Logic.BLL;
using KMFrame.Core;
using LGCourt.Logic.NBL.DBEntities;
using lgweb.common;
using LGCourt.Logic.Common;

namespace lgweb.inside.department
{
    public partial class notice : NeedValidatePage
    {
        private int _pageIndex = 1;
        private string _Keyword = string.Empty;
        public string _DeptID = "0";
        public string _DetpName = string.Empty;
        public string _picUrl = string.Empty;
        public string _cate = "0";
        public string _deptCode = string.Empty;
        protected new void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            if (!this.IsPostBack)
            {
                this.hdOADomain.Value = System.Configuration.ConfigurationManager.AppSettings["OADomain"];
                _picUrl = System.Configuration.ConfigurationManager.AppSettings["InfoManage"];
                _picUrl = string.IsNullOrEmpty(_picUrl) ? "/lgmanage/Systems/upload/" : _picUrl;
                GetParam();
                GetInfo();
                GetList();               
            }
        }

        private void GetParam()
        {
            this._Keyword = string.IsNullOrEmpty(Request.QueryString["Keyword"]) ? "" : Request.QueryString["Keyword"];
            this._pageIndex = string.IsNullOrEmpty(Request.QueryString["PageIndex"]) ? 1 : Convert.ToInt32(Request.QueryString["PageIndex"]);
            this._DeptID = string.IsNullOrEmpty(Request.QueryString["deptid"]) ? "0" : Request.QueryString["deptid"];
            this._cate = string.IsNullOrEmpty(Request.QueryString["cate"]) ? "0" : Request.QueryString["cate"];
            this._deptCode = string.IsNullOrEmpty(Request.QueryString["Code"]) ? "ZZC" : Request.QueryString["Code"].ToString();
            this.txtKeyword.Value = _Keyword;
        }
        //获取部门信息
        private void GetInfo()
        {
            ColInfo colInfoBLL = new ColInfo();
            DeptClassCondition param = new DeptClassCondition();
            //取部门
            if (_DeptID == "0")
            {
                DepartmentHandler departmentHandler = new DepartmentHandler();
                Department department = departmentHandler.GetDepartmentInfo(_deptCode);
                if (department != null)
                {
                    _DetpName = department.Name;
                }
                //根据名称取部门ID
                param.Source = _DetpName;
            }
            else
            {
                param.ClassID = int.Parse(_DeptID);
            }
            param.Name = "部门";
            V_DICT_SOURCE deptInfo = colInfoBLL.GetDeptSourceInfo(param);
            if (deptInfo == null)
            {
                deptInfo = new V_DICT_SOURCE();
                deptInfo.ID = 1;
            }
            _DeptID = deptInfo.ID.ToString();
            _DetpName = deptInfo.Source;
          
            this.spDeptLink.InnerHtml = _DetpName;
            this.spDeptLink.HRef = "/inside/department/index.aspx?deptid=" + this._DeptID;
            this.spNewsName.InnerHtml = "信息报送";

            //取信息维护员
            DeptCondition deptParam = new DeptCondition();
            deptParam.DeptID = deptInfo.ID.GetValueOrDefault(0);    
            LGFY_Platform_Index deptIndex = colInfoBLL.GetDeptIndexInfo(deptParam);
            spInfoEditer.InnerText = deptIndex == null ? "" : deptIndex.Managers;
        }
        private void GetList()
        {
            OA bll = new OA();
            OANoticeCondition param = new OANoticeCondition();
            param.UserID = this.SessionInfo.UserID;
            param.PageSize = 20;
            param.PageIndex = this._pageIndex;
            param.Keyword = _Keyword;
            param.DeptName = _DetpName;
            PageResult result = (PageResult)bll.GetXinXiBaoSongPage(param);

            if (result != null && result.ResultList != null)
            {
                this.rptNoticeList.DataSource = (List<vOAXinXiBaoSong>)result.ResultList;
                this.rptNoticeList.DataBind();
                this.pager1.RecordCount = result.TotalCount;
                this.pager1.TotalPage = result.PageCount;
                this.pager1.PageIndex = this._pageIndex;
                this.pager1.PageSize = 20;
                this.pager1.LinkUrl = string.Format("/inside/department/notice.aspx?Keyword={0}&PageIndex={1}&deptid={2}&cate=1", Server.UrlEncode(this._Keyword), this._pageIndex, this._DeptID);
            }
        }
    }
}